<template>
  <div class="blog-detail">
    <div class="blog-img">
      <a-image :src="blog.header_image" :alt="blog.title" />
    </div>
    <div class="blog-category">{{ blog.category.name }}</div>
    <div class="blog-title">{{ blog.title }}</div>
    <div class="time-wrapper">
      <span class="dot"></span>
      <span class="time">{{ blog.published_at }}</span>
    </div>
    <div class="blog-content">
      <div class="content-text markdown-body" v-html="renderedContent"></div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, computed, defineComponent } from 'vue'
import { defineProps } from 'vue'
import MarkdownIt from 'markdown-it'

const md = new MarkdownIt({
  html: true,
  breaks: true,
  linkify: true,
  typographer: true
})

const props = defineProps({
  blog: {
    type: Object,
    default: () => ({})
  }
})

const renderedContent = computed(() => {
  console.log('Content:', props.blog?.content)
  if (!props.blog?.content) return ''
  return md.render(props.blog.content)
})
</script>

<script lang="ts">
export default defineComponent({
  name: 'BlogDetail'
})
</script>

<style lang="scss" scoped>
.blog-detail {
  padding: 20px 0;
}
.blog-img{
  width: 100%;
  height: 529px;
  img{
    width: 100%;
    height: 100%;
    object-fit: cover;
  }
}
.blog-content{
  margin-top: 20px;
}
.content-text{
  margin-bottom: 20px;
}

.blog-category {
  font-size: 18px;
  color: #333;
}

.blog-title {
  font-size: 32px;
  font-weight: 600;
  line-height: 1.4;
}

.time-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.dot {
  width: 8px;
  height: 8px;
  background-color: #999;
  border-radius: 50%;
}

.time {
  font-size: 16px;
  color: #999;
}

.blog-content {
  font-size: 16px;
  line-height: 1.8;
  color: #333;
}

.content-text {
  margin-bottom: 32px;
}

:deep(.markdown-body) {
  h1, h2, h3, h4, h5, h6 {
    margin-top: 24px;
    margin-bottom: 16px;
    font-weight: 600;
    line-height: 1.25;
  }

  h1 { font-size: 2em; }
  h2 { font-size: 1.5em; }
  h3 { font-size: 1.25em; }
  h4 { font-size: 1em; }

  p {
    margin-bottom: 16px;
  }

  img {
    max-width: 100%;
    height: auto;
    margin: 16px 0;
  }

  ul, ol {
    padding-left: 2em;
    margin-bottom: 16px;
  }

  li {
    margin: 0.25em 0;
  }

  blockquote {
    padding: 0 1em;
    color: #6a737d;
    border-left: 0.25em solid #dfe2e5;
    margin: 0 0 16px 0;
  }

  code {
    padding: 0.2em 0.4em;
    margin: 0;
    font-size: 85%;
    background-color: rgba(27,31,35,0.05);
    border-radius: 3px;
  }

  pre {
    padding: 16px;
    overflow: auto;
    font-size: 85%;
    line-height: 1.45;
    background-color: #f6f8fa;
    border-radius: 3px;
    margin-bottom: 16px;
  }

  pre code {
    padding: 0;
    margin: 0;
    font-size: 100%;
    word-break: normal;
    white-space: pre;
    background: transparent;
    border: 0;
  }

  a {
    color: #0366d6;
    text-decoration: none;
    &:hover {
      text-decoration: underline;
    }
  }

  hr {
    height: 0.25em;
    padding: 0;
    margin: 24px 0;
    background-color: #e1e4e8;
    border: 0;
  }

  table {
    display: block;
    width: 100%;
    overflow: auto;
    margin-bottom: 16px;
    border-spacing: 0;
    border-collapse: collapse;
  }

  table th {
    font-weight: 600;
  }

  table th,
  table td {
    padding: 6px 13px;
    border: 1px solid #dfe2e5;
  }

  table tr {
    background-color: #fff;
    border-top: 1px solid #c6cbd1;
    &:nth-child(2n) {
      background-color: #f6f8fa;
    }
  }
}
</style> 